package com.xdf.testkafk.rocket;

import com.alibaba.fastjson.JSON;
import com.xdf.testkafk.vo.KafkaMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author chanchaw
 * @create 2025-11-01 8:30
 */
@Slf4j
@Component
@RocketMQMessageListener(
        topic = "imooc-study-rocketmq", // 消费指定的 topic
        consumerGroup = "cc-springboot-rocketmq-consumer-tag-string", // 消费者组，组内的多个消费者消费同一个 topic
        selectorExpression = "cc" // 消费指定的 tag，起到过滤作用，不消费其他 tag 的消息
)
public class RocketMQConsumerTagString implements RocketMQListener<String> {
    @Override
    public void onMessage(String s) {
        KafkaMessage msg = JSON.parseObject(s, KafkaMessage.class);
        log.info("消费者 RocketMQConsumerTagString 接收到的数据反序列化后是：[{}]", JSON.toJSONString(msg));
    }
}
